import java.awt.GridLayout;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

public class Main {
	
	final static ChooserGUI chooserframe = new ChooserGUI();
	final static PersonGUI personframe = new PersonGUI();
	final static EmployeeGUI employeeframe = new EmployeeGUI();
	final static StudentGUI studentframe = new StudentGUI();
	
	public static void main(String[] args) {
		chooserframe.setLocation(300,300);
		chooserframe.setVisible(true);
	}
}

class ChooserGUI extends JFrame {
	
	static JRadioButton personbutton;
	static JRadioButton employeebutton;
	static JRadioButton studentbutton;
	
	public ChooserGUI() {
		setLayout(new GridLayout(2, 1, 5, 5));
		setTitle("Choose a type to add");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(250,175);
		
		JPanel paneltop = new JPanel();
		paneltop.setLayout(new GridLayout(3,1,5,5));
		paneltop.setSize(250, 125);
		add(paneltop);
		
		JPanel panelbottom = new JPanel();
		panelbottom.setLayout(new GridLayout(1,2,5,5));
		panelbottom.setSize(250,25);
		add(panelbottom);
		
		personbutton = new JRadioButton("Person");
		paneltop.add(personbutton);
		
		employeebutton = new JRadioButton("Employee");
		paneltop.add(employeebutton);
		
		studentbutton = new JRadioButton("Student");
		paneltop.add(studentbutton);
		
		ButtonGroup group = new ButtonGroup();
		group.add(personbutton);
		group.add(employeebutton);
		group.add(studentbutton);
		
		JButton submit = new JButton("Submit");
		panelbottom.add(submit);
		ChooserSubmitListener listener1 = new ChooserSubmitListener();
		submit.addActionListener(listener1);
		
		
		JButton cancel = new JButton("Cancel");
		cancel.addActionListener(new ChooserCancelListener());
		panelbottom.add(cancel);
		
	}
}

class ChooserSubmitListener implements ActionListener {
	@Override
	public void actionPerformed(ActionEvent e) {
		if (ChooserGUI.personbutton.isSelected()) {
			Main.chooserframe.setVisible(false);
			Main.personframe.setLocation(300, 300);
			Main.personframe.setVisible(true);
		}
		
		if (ChooserGUI.employeebutton.isSelected()) {
			Main.chooserframe.setVisible(false);
			Main.employeeframe.setLocation(300, 300);
			Main.employeeframe.setVisible(true);
		}
		
		if (ChooserGUI.studentbutton.isSelected()) {
			Main.chooserframe.setVisible(false);
			Main.studentframe.setLocation(300, 300);
			Main.studentframe.setVisible(true);
		}
	}
}

class ChooserCancelListener implements ActionListener {
	@Override
	public void actionPerformed(ActionEvent e) {
		System.exit(0);
	}
}
